import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author wonghiu
 * @Date 2021/8/23 19:26
 * @Version 1.0.1
 *
 */
public class ten {
    public static void main(String[] args) {
//        new ten().check1(new int[]{1,-2,4,5,-1,1});
//        new ten().check3(new int[]{2,2,1});
        new ten().check2(new int[]{1,3,-1,-3,5,3,6,7},3);
    }
    // 连续最大和
    public void check1(int[] nums){
        int[] dp = new int[nums.length];
        dp[0] = Math.max(nums[0],0);
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(dp[i-1]+nums[i],0);
        }
        System.out.println(dp[dp.length-1]);
    }
    // 滑动窗口的最大值 1,3,-1,-3,5,3,6,7
    public void check2(int[] nums,int k){
        int left = 0;
        int right = 0;
        int n = nums.length;
        LinkedList<Integer> queue = new LinkedList<>();
        int[] maxRes = new int[nums.length-k+1];

        while (right<n){
            if (right-left+1 > k){
                int cur = nums[queue.getFirst()];
                if (nums[left]==cur){
                    queue.pollFirst();
                }
                maxRes[left]=cur;
                left++;
            }
            while (!queue.isEmpty() && nums[queue.getLast()]<nums[right]){
                queue.removeLast();
            }
            queue.add(right);
            right++;
        }
        maxRes[maxRes.length-1] = queue.pollFirst();
        System.out.println(Arrays.toString(maxRes));
    }

    // 位运算
    public void check3(int[] nums){
        int res = nums[0];
        for (int i = 1; i <nums.length ; i++) {
            res^=nums[i];
        }
        System.out.println(res);
    }
}

